﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Loong.Model;

namespace QYWebSiteBN
{
    public class TranslateContentRule
    {
        private static List<TranslateContentRuleInfo> rulelist = new List<TranslateContentRuleInfo>();

        private static TranslateContentRule rule=null;

        private TranslateContentRule()
        {
            if (rule == null)
            {
                rule = new TranslateContentRule();
            }
        }

        public static int Count
        {
            get { return rulelist.Count; }
        }

        public static void Add(TranslateContentRuleInfo info)
        {
            rulelist.Add(info);
        }

        public static TranslateContentRuleInfo Get(int index)
        {
           return rulelist[index];
        }

        public static void Edit(int index, TranslateContentRuleInfo info)
        {
            rulelist[index] = info;
        }

        public static void Delete(int index)
        {
            rulelist.RemoveAt(index);
        }

        public static void Load(string filename)
        {
            Loong.Store.ObjectStoreQueue store = new Loong.Store.ObjectStoreQueue(filename);
            for (int i = 0; i < store.Count; i++)
            {
                rulelist.Add((TranslateContentRuleInfo)store.Dequeue());
            } 
        }

        public static void Save(string filename)
        {
            try
            {
                Loong.Store.ObjectStoreQueue store = new Loong.Store.ObjectStoreQueue(filename);

                foreach (TranslateContentRuleInfo info in rulelist)
                {
                    store.Enqueue(info);
                }

                store.Save();
            }
            catch (Exception e)
            {
                throw e;
            }
        }
    }
}
